<?php namespace Home\Controller;
use Hdphp\Controller\Controller;

class CartController extends CommonController{
	private $model;
	public function __init(){
		//调用CommonController里面的构造函数
		parent::__init();
		$this->model = new \Admin\Model\Goods;
	}
	//购物车页
	public function index(){
		//购物车数据
		$c = Cart::getGoods();
		if($c){
			//新数组 放商品照片 然后传到View
		$d = array();
		foreach ($c as $k => $v) {
			$d[$k]=$this->model->where("gid=".$v['id'])->pluck('gpic');
		}
		//商品图片
		View::with('d',$d);
		//购物车数据
		View::make();
		}
		View::error('请重新登录',U('Login/index'));
	}
	//AJAX删除
	public function del(){
		$sid = Q('post.sid',0,'intval');
		unset($_SESSION['goods'][$sid]);
		Cart::del("{$sid}");
		View::success('删除成功');
	}
	
}
	